home *** CD-ROM | disk | FTP | other *** search
/ Clinical Endocrinology / Clinical Endocrinology.iso / mac / 00000000 / Bookmark.dir-old / 00001_Script_1 next >
Text File  |  1995-11-09  |  6KB  |  250 lines

  1. on init
  2.   
  3.   global installedFolderpath, gReadBkMarks, marksList, refList
  4.   global bookmarkChoice
  5.   
  6.   set marksList = []
  7.   set the keyDownScript = "doAddReturn"
  8.   set bookmarkChoice = 1
  9.   
  10.   put fileIO(mNew, "read", installedFolderpath & "Bookmark.DAT") into gReadBkMarks
  11.   
  12.   if not objectp(gReadBkMarks) then
  13.     alert "Sorry. Can't find bookmarks data."
  14.   else
  15.     readBookmarks -- reads the txt file and puts it into a list
  16.     makeLinkLists -- splits this list into a reference list and link list
  17.     displayRefs -- shows the refList, item by item, in the display field
  18.     if count(marksList) > 0 then
  19.       hilite line bookmarkChoice of field "Display Field"
  20.     else
  21.       set bookmarkChoice = 0
  22.     end if
  23.     
  24.   end if
  25.   
  26. end init
  27. -----------------------------------------------------------------------------------
  28. on readBookmarks
  29.   
  30.   global gReadBkMarks, marksList
  31.   
  32.   put gReadBkMarks(mReadFile) into myText
  33.   if myText <> "" then
  34.     
  35.     put the number of lines in myText into theLines
  36.     repeat with i = 1 to theLines
  37.       
  38.       put line i of myText into myItem
  39.       add marksList, myItem
  40.       
  41.     end repeat
  42.   end if
  43.   
  44.   gReadBkMarks(mDispose)
  45.   
  46. end readBookmarks
  47. ------------------------------------------------------------------
  48. -- This handler takes marksList made from the txt file
  49. -- and splits it, using two functions, into two lists
  50. -- 
  51. on makeLinkLists
  52.   
  53.   global marksList, refList, linkList
  54.   
  55.   set refList = []
  56.   set linkList = []
  57.   
  58.   repeat with i = 1 to count(marksList)
  59.     put getAt(marksList, i) into listString
  60.     
  61.     put stripStart(listString) into refString
  62.     add(refList, refString)
  63.     
  64.     put stripEnd(listString) into linkString
  65.     add(linkList, linkString)
  66.     
  67.   end repeat
  68.   
  69. end makeLinkLists
  70. -----------------------------------------------------
  71. -- This is a function!!
  72. -- To use this, use the syntax below
  73. -- put stripStart( <put a string in here> ) into newString
  74. -- where newstring is the stripped word resulting
  75. -- from this function
  76. -- StripEnd uses the same syntax.
  77.  
  78. on stripStart listString
  79.   
  80.   put the number of chars in listString into theChars
  81.   repeat with i = 1 to theChars
  82.     if char i of listString = "*" then exit repeat
  83.     put char 1 to i of listString into theStart
  84.   end repeat
  85.   return theStart
  86.   
  87. end stripStart
  88. -----------------------------------------------------
  89. on stripEnd listString
  90.   
  91.   put the number of chars in listString into theChars
  92.   repeat with i = 1 to theChars
  93.     if char i of listString = "*" then exit repeat
  94.   end repeat
  95.   
  96.   put (i + 1) into newStart
  97.   
  98.   put char newStart to theChars of listString into theEndBit
  99.   return theEndBit
  100.   
  101. end stripEnd
  102. -----------------------------------------------------
  103. on displayRefs
  104.   
  105.   global refList
  106.   
  107.   put "" into theText
  108.   
  109.   put count(refList) into theItems
  110.   
  111.   repeat with i = 1 to theItems
  112.     
  113.     put getAt(refList, i) into theRef
  114.     if i =  1 then
  115.       put theRef after theText
  116.     else
  117.       put RETURN & theRef after theText
  118.     end if
  119.     
  120.   end repeat
  121.   
  122.   put theText into field "Display Field"
  123.   
  124. end displayRefs
  125. -----------------------------------------------------
  126. on addBookmark
  127.   
  128.   global refList, linkList, marksList, parentPath, bookmarkChoice
  129.   
  130.   put the text of field "User Field" into newRef
  131.   if newRef = "" then
  132.     alert "Please name the bookmark first."
  133.   else
  134.     add refList, newRef 
  135.     getParentPath
  136.     add linkList, parentPath 
  137.     add marksList, newRef & "*" & parentPath
  138.     writeBookMarks
  139.     displayRefs
  140.     set bookmarkChoice = count(marksList)
  141.     hilite line bookmarkChoice of field "Display Field"
  142.   end if
  143.   
  144.   
  145. end addBookmark
  146. -------------------------------------------------------------
  147. on deleteBookmark
  148.   
  149.   global refList, linkList, marksList, parentPath, bookmarkChoice
  150.   
  151.   if count(marksList) > 0 then
  152.     
  153.     deleteAt marksList, bookmarkChoice
  154.     
  155.     makeLinkLists
  156.     writeBookMarks
  157.     displayRefs
  158.     
  159.     if count(marksList) > bookmarkChoice then
  160.       set bookmarkChoice = count(marksList)
  161.       hilite line bookMarkChoice of field "Display Field"
  162.     else
  163.       set bookmarkChoice = count(marksList)
  164.       if bookmarkChoice <> 0 then hilite line bookMarkChoice of field "Display Field"
  165.     end if
  166.     
  167.   else
  168.     alert "Choose a Bookmark to delete."
  169.   end if
  170.   
  171.   
  172. end deleteBookmark
  173. -------------------------------------------------------------
  174. on getParentPath
  175.   
  176.   global parentPath
  177.   
  178.   tell the stage
  179.     global parentPath
  180.     put the pathname & the movieName into parentPath
  181.   end tell
  182.   
  183. end getParentPath
  184. -------------------------------------------------------------
  185. on writeBookMarks
  186.   
  187.   global refList, linkList, marksList, gWriteBkMarks, installedFolderpath
  188.   
  189.   if count(refList) <> count(linkList) then
  190.     alert "Missing some data! Try opening Bookmark.DAT" & RETURN &¼
  191. "and erasing all entries! Start from scratch."
  192.   end if
  193.   
  194.   put "" into newData
  195.   
  196.   repeat with i = 1 to count(marksList)
  197.     if i = 1 then
  198.       put getAt(marksList, i) after newData
  199.     else
  200.       put RETURN & getAt(marksList, i) after newData
  201.     end if
  202.   end repeat
  203.   
  204.   put fileIO(mNew, "write", installedFolderpath & "Bookmark.DAT") into gWriteBkMarks
  205.   if not objectP(gWriteBkMarks) then
  206.     alert "Sorry can't find bookmark data."
  207.   else
  208.     gWriteBkMarks(mWriteString, newData)
  209.     gWriteBkMarks(mDispose)
  210.   end if
  211.   
  212. end writeBookMarks
  213. -----------------------------------------------------
  214. on chooseLine
  215.   global bookmarkChoice
  216.   
  217.   put the mouseLine into bookmarkChoice
  218.   if bookmarkChoice > 0 then
  219.     hilite line bookmarkChoice of field "Display Field"
  220.   end if
  221.   
  222. end chooseLine
  223. -----------------------------------------------------
  224. on goToBookMark
  225.   
  226.   global bookmarkChoice, linkList
  227.   
  228.   if bookmarkChoice > count(linkList) then
  229.     alert "Please, choose a bookmark."
  230.   else if count(linkList) < 1 then
  231.     alert "There are no bookmarks. Bookmarks must be added first."
  232.   else
  233.     put getAt(linkList, bookmarkChoice) into newPath
  234.     tell the stage
  235.       go movie newPath
  236.     end tell
  237.     
  238.   end if
  239.   
  240. end goToBookMark
  241. ------------------------------------------------------
  242. on doAddReturn
  243.   
  244.   if the key = RETURN then
  245.     addBookmark
  246.     dontPassEvent
  247.   end if
  248.   
  249. end doAddReturn
  250.